<?php

class Silk_Mapi_Block_Adminhtml_Version_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId("versionGrid");
        $this->setDefaultSort("id");
        $this->setDefaultDir("DESC");
        $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getModel("mapi/version")->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        $this->addColumn('id', array(
            "header" => Mage::helper("mapi")->__("ID"),
            "width" => "50px",
            "type" => "number",
            "index" => "id",
        ));

        $this->addColumn('version', array(
            "header" => Mage::helper("mapi")->__("版本号"),
            "width" => "100px",
            "index" => "version",
        ));

        $this->addColumn('title', array(
            "header" => Mage::helper("mapi")->__("标题"),
            "index" => "title",
        ));

        $this->addColumn('url', array(
            "header" => Mage::helper("mapi")->__("安装包路径"),
            "index" => "url",
        ));

        $this->addColumn('type', array(
            "header" => Mage::helper("mapi")->__("APP类型"),
            "width" => "100px",
            "index" => "type",
            "type" => "options",
            "options" => Mage::helper('mapi')->getAppType()
        ));

        $this->addColumn('status', array(
            "header" => Mage::helper("mapi")->__("是否启用"),
            "width" => "100px",
            "index" => "status",
            "type" => "options",
            "options" => Mage::getSingleton('mapi/version')->getStatusOptions()
        ));

        $this->addColumn('force', array(
            "header" => Mage::helper("mapi")->__("是否强制更新"),
            "width" => "100px",
            "index" => "force",
            "type" => "options",
            "options" => Mage::getSingleton('mapi/version')->getForceOptions()
        ));

        return parent::_prepareColumns();
    }

    public function getRowUrl($row)
    {
        return $this->getUrl("*/*/edit", array("id" => $row->getId()));
    }

    protected function _prepareMassaction()
    {
        $this->setMassactionIdField('id');
        $this->getMassactionBlock()->setFormFieldName('ids');
        $this->getMassactionBlock()->setUseSelectAll(true);
        $this->getMassactionBlock()->addItem('remove_manufacturer', array(
            'label' => Mage::helper('mapi')->__('Remove'),
            'url' => $this->getUrl('*/adminhtml_version/massRemove'),
            'confirm' => Mage::helper('mapi')->__('Are you sure?')
        ));
        return $this;
    }
}